package com.qupai.controller.admin;

import com.qupai.dto.RegistrationPageQueryDTO;
import com.qupai.dto.RegistrationRejectionDTO;
import com.qupai.entity.Registration;
import com.qupai.result.PageResult;
import com.qupai.result.Result;
import com.qupai.service.IRegistrationService;
import com.qupai.vo.RegistrationVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

@RestController("adminRegistrationController")
@RequestMapping("/admin/registration")
@Slf4j
@Tag(name = "志愿-活动报名管理接口")
@RequiredArgsConstructor
public class RegistrationController {

    private final IRegistrationService registrationService;

    /**
     * 报名分页查询
     */
    @GetMapping("/conditionSearch")
    @Operation(summary = "报名分页查询")
    public Result<PageResult> conditionSearch(@ParameterObject RegistrationPageQueryDTO registrationPageQueryDTO) {
        PageResult pageResult = registrationService.conditionSearch(registrationPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 报名详情
     */
    @GetMapping("/details/{registrationId}")
    @Operation(summary = "查询报名详情")
    public Result<RegistrationVO> details(@PathVariable("registrationId") Long registrationId) {
        Registration registration = registrationService.getById(registrationId);
        RegistrationVO registrationVO=new RegistrationVO();
        BeanUtils.copyProperties(registration,registrationVO);
        //RegistrationVO registrationVO = registrationService.details(registrationId);
        return Result.success(registrationVO);
    }

    /**
     * 完成报名
     */
    @PutMapping("/complete/{id}")
    @Operation(summary = "完成报名")
    public Result<RegistrationVO> complete(@PathVariable("id") Long id) {
        RegistrationVO registrationVO=registrationService.complete(id);
        return Result.success(registrationVO);
    }

    /**
     * 拒单
     */
    @PutMapping("/rejection")
    @Operation(summary = "拒单")
    public Result<String> rejection(@RequestBody RegistrationRejectionDTO registrationRejectionDTO) {
        registrationService.rejection(registrationRejectionDTO);
        return Result.success();
    }

}
